from google.appengine.ext import db

class role(db.Model):
    name = db.StringProperty()

def addRole(new_role):
    if exist(new_role):
        return False
    new_role.put()
    return True

def exist(new_role):
    for role in roles:
        if role.name == new_role.name:
            return True
    return False
    
def removeRole(role):
    if exist(role):
        roles.remove(role)        
        return True
    else:
        return False
    
def modifyRole(old, new):
    for i in range(len(roles)):
        if roles[i].name == old:
            roles[i].name = new
            return
    return

def rolesToString():
    s = ''
    for r in roles:
        if r.name != None:
            s+=(r.name + '; ')
    return s
    
roles = db.GqlQuery('SELECT * FROM role')
